{% extends 'base.html' %}{% block content %}{% load custom_filter %}

<div class="modal fade" id="edit_balancer" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="edit_balancer_title"></h4><small id="edit_balancer_mtitle"></small>
            </div>
            <div class="modal-body">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_base_config" data-toggle="tab" id="a_default_conf">基础配置</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_base_config">
                            <form class="form-horizontal" id="form_base_config">
                                <input type="text" name="proxy_config_id" id="input_proxy_config_id" hidden>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">网站名</label>
                                    <div class="col-sm-9" id="div_proxy_name">
                                        <input type="text" class="form-control" name="proxy_proxy_name" id="input_proxy_proxy_name" placeholder="用于描述被代理网站的名称" onblur="check_form(this)">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">域名</label>
                                    <div class="col-sm-9" id="div_domain_name">
                                        <input type="text" class="form-control" name="proxy_domain_name" id="input_proxy_domain_name" placeholder="被代理网站的域名" onblur="check_form(this)">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">URL</label>
                                    <div class="col-sm-9" id="div_proxy_URL">
                                        <input type="text" class="form-control" name="proxy_proxy_URL" id="input_proxy_proxy_URL" placeholder="用于描述被代理网站IP" onblur="check_form(this)">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">服务端口</label>
                                    <div class="col-sm-9" id="div_listen">
                                        <input type="text" class="form-control" name="proxy_listen" id="input_proxy_listen" placeholder="反向代理对应请求转发端口" onblur="check_form(this)">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">* 访问日志</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="proxy_access_log" id="input_proxy_access_log" placeholder="请求日志路径">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">* 错误日志</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="proxy_error_log" id="input_proxy_error_log" placeholder="错误日志路径">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">* 站点权限</label>
                                    <div class="col-sm-9">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="proxy_ip_hash" id="check_proxy_ip_hash"> 是否将站点设置为公开资源
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">* WebVPN</label>
                                    <div class="col-sm-9">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="proxy_vpn" id="proxy_vpn_check" onchange="check_form(this)"> 是否对该站点启用WebVPN
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">* 描述</label>
                                    <div class="col-sm-9">
                                        <textarea class="form-control" rows="4" name="proxy_description" id="input_proxy_description" placeholder="此反向代理网站详细描述"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-12">
                                        <span class="control-label pull-right">
                                            <small>反向代理基础配置（* 为可选项）</small>
                                        </span>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- /.tab-pane -->
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="save_balancer()">保存</button>
            </div>
        </div>
    </div>
</div>


<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-header with-border">
                <button type="button" class="btn btn-primary pull-left" onclick="edit_balancer(1)">发布资源</button>
                <div class="input-group pull-right" style="width: 250px;">
                    <input type="text" name="proxy_filter" id="input_proxy_filter" class="form-control pull-right" placeholder="请输入名称或域名" onkeydown='if(event.keyCode==13){proxy_filter()}'>
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default" onclick="proxy_filter()"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body no-padding">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>网站名</th>
                            <th>域名</th>
                            <th>ip</th>
                            <th>协议</th>
                            <th>端口</th>
                            <th>状态</th>
                            <th>检测方式</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="col-sm-2">
                               <button type="button" class="btn btn-default btn-xs col-sm-10">校主页</button>
                            </td>
                            <td>
                                http://www.bupt.edu.cn
                            </td>
                            <td>
                                10.3.19.81
                            </td>
                            <td>
                                <button class="btn btn-primary btn-xs" disabled>HTTP</button>
                            </td>
                            <td>
                                80
                            </td>
                            <td>
                                <button type="button" class="btn btn-success btn-xs">启用</button>
                            </td>
                            <td>
                                <button type="button" class="btn btn-warning btn-xs" disabled>TCP</button>
                            </td>
                            <td>
                                2017-07-06 22:29:34
                            </td>
                            <td>
                                <button type="button" class="btn btn-primary btn-xs")>查看</button>
                                <button type="button" class="btn btn-danger btn-xs" )>编辑</button>
                                <button type="button" class="btn btn-danger btn-xs" )>删除</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
                <ul class="pagination pagination-sm no-margin pull-right">
                    {% if proxy.has_previous %}
                    <li><a href="?page={{ proxy.previous_page_number }}&filter={{ filter }}" class="prev">{{ previous_link_decorator|safe }}上一页</a></li>
                    {% else %}
                    <li class="paginate_button previous disabled"><span class="disabled prev">{{ previous_link_decorator|safe }}上一页</span></li>
                    {% endif %} {% if proxy.has_next %}
                    <li><a href="?page={{ proxy.next_page_number }}&filter={{ filter }}" class="next">下一页{{ next_link_decorator|safe }}</a></li>
                    {% else %}
                    <li class="paginate_button next disabled"><span class="disabled next">下一页{{ next_link_decorator|safe }}</span></li>
                    {% endif %}
                    <li class="paginate_button previous disabled">
                        <span>第 {{ proxy.number }} 页 - 共 {{ proxy.paginator.num_pages }} 页</span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>


    <script>
    $('#menu_proxy_config').addClass('active')
    $('#page_header').text('反向代理配置')
    $('#page_header_descript').text('用于管理 Nginx 代理主机相关配置')
    $('#page_nav').text('服务管理')
    $('#page_name').text('负载均衡配置')

    function edit_balancer(create, config_id) {
        $('#a_default_conf').trigger('click')
        if (create == 1) {
            $('#edit_balancer_title').text('添加资源')
            $('#edit_balancer_mtitle').text('添加被代理服务器')
            $('#input_proxy_config_id').val('0')
            $('#input_proxy_proxy_name').val('')
            $('#input_proxy_domain_name').val('')
            $('#input_proxy_listen').val('')
            $('#input_proxy_server_name').val('')
            $('#input_proxy_access_log').val('')
            $('#input_proxy_error_log').val('')
            $('#check_proxy_ip_hash').attr('checked', false)
            $('#check_proxy_http_check').attr('checked', false)
            $('#div_upstream_list').empty()
            $("[data-mask]").inputmask()
            $('#edit_balancer').modal('show')
        }
    }
    </script>
{% endblock %}

